{extend name="public/base" /} 
{block name="style"}
	<link href="__CSS__/cash.css" rel="stylesheet">	
{/block}
{block name="body"}
<div class=" gray-bg" data-scroll="y" data-scroll-destroy="true" id="container" scroll="true">
	<div class="ibox float-e-margins" style="width:47%;float: left;margin-top: 20px;margin-left: 20px;">
		<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="input-group m-b">
		        <input type="text" id="key" name="key" class="form-control" placeholder="搜索会员卡号/手机号/姓名">
		        <span class="input-group-addon" > <img src="__IMG__/search.png" /></span>
		        <span class="input-group-addon" onclick="adduser()"><img src="__IMG__/adduser.png" /></span>
		    </div>
  		</div>
  		<div  id="member_info" style="display: none;" >
			<p><span class="m_rs_pan">会员卡号：</span><span id="no"></span><span class="card_type"></span></p>
			<p><th class="m_rs_pan">姓名：<span id="name"></span></th>
		   		<span class="m_rs_pan">手机号：<span id="mobile"></span></span>
			   	<span class="m_rs_pan">余额：<span id="money"></span></span>
		    	<span class="m_rs_pan">积分：<span id="score"></span></span>
			</p>
  		</div>
 		<div class="row line" ></div>
		<div class="row" >
			<div class="input-group m-b" style="width: 100%;">
		        <span class="rs_pan">账单金额<span class="m_rs_pan">(元)</span></span>
		        <input onkeyup="keyup_price(this)" type="text" id="price" class="form-control rs_input" placeholder="填写充值金额"> 
		    </div>
  		</div>
  		<div class="row line" ></div>
		<div class="row" >
			<div class="input-group m-b" style="width: 100%;">
		        <span class="rs_pan">折后金额<span class="m_rs_pan">(元)</span></span>
		        <input type="text" id="zhe_price" readonly="readonly" class="form-control rs_input" placeholder=""> 
		    </div>
  		</div>
  		<div class="row line"></div>
		<div class="row" >
			<div class="input-group m-b" style="width: 100%;">
		        <span class="rs_pan">赠送积分</span>
		        <input type="text" id="zs_score" readonly="readonly" class="form-control rs_input" placeholder=""> 
		    </div>
  		</div>
  		<div class="row line" ></div>
		<div class="row" >
			<div class="input-group m-b" style="width: 100%;">
		        <span class="b_rs_pan">应收金额<span class="m_rs_pan">(元)</span></span>
		        <input type="text" id="ys_money" readonly="readonly" class="form-control rs_input" placeholder=""> 
		    </div>
  		</div>
  		<div class="row line" ></div>
		<div class="row" >
			<div class="input-group m-b" style="width: 100%;">
		       <button onclick="search_emp()" tabindex="-1" class="btn btn-white" type="button"><i class="fa fa-plus"></i>选择导购</button>
		       <br />
		       <div  id="emp_info"  style="display: none;">
				<p><span class="m_rs_pan ">导购员工号:<span id="zno"></span></span>
				   <span class="m_rs_pan r1">职务:<span id="zname"></span></span>
				</p>
  			   </div>
                <textarea id="ccomment" name="comment" style="height: 80px;width: 100%;" class="form-control" required="" placeholder="填写备注" aria-required="true"></textarea>
		    </div>
  		</div>
        </div>
  	</div>
	<div  style="width:47%;display:inline-block;float: left;margin-top: 40px;margin-left: 20px;background-color: #fff;">
			<div class="wrapper wrapper-content animated fadeInRight" style="padding-top: 5px;padding-left: 25px;">
		<div class="row">
			<div class="input-group m-b" style="width: 100%;margin-bottom: 3px;">
		         <div style="float:left"><span class="b_rs_pan" >支付方式?</span></div>
		        <div style="float:right;margin-right: 30px;"> 找零:<span style="float:right;margin-right: 25px;" class="rs_pan" id="zhaoling"></span></div>
		    </div>
  		</div>
 		<div class="row line" style="margin-bottom: 3px;"></div>
		<div class="" >
			<ul class="nav pay_method">
				<li class="sku" onClick="switch_spec(this)" data = "1">
					<p><img src="__IMG__/pay.png"/></p>
					<p><span class="p_name">现金</span></p>
					<s></s>
				</li>
				<li class="sku" onClick="switch_spec(this)" data = "3">
					<p><img src="__IMG__/weixin.png" /></p>
					<p><span class="p_name">微信</span></p>
					<s></s>
				</li>
				<li class="sku" onClick="switch_spec(this)" data = "4">
					<p><img src="__IMG__/alipay.png"/></p>
					<p><span class="p_name">支付宝</span></p>
					<s></s>
				</li>
				<li class="sku " onClick="switch_spec(this)" data = "5">
					<p><img src="__IMG__/card.png"/></p>
					<p><span class="p_name">银行卡</span></p>
					<s></s>
				</li>
				<li class="sku" onClick="switch_spec(this)">
					<p><img src="__IMG__/card.png"/></p>
					<p><span class="p_name">自定义</span></p>
					<s></s>
				</li>
			</ul>
  		</div>
  		<div class="row line" ></div>
  		<div class="row" >
			<div class="input-group m-b" style="width: 100%;">
		        <span class="b_rs_pan">付款金额<span class="m_rs_pan">(元)</span></span>
		        <input type="text" onkeyup="keyup_pay(this)" id="pay_money" class="form-control rs_input1 " placeholder="0.00￥"> 
		    </div>
  		</div>
  		<div class="row line" ></div>
		<div class="row" style="margin-left: 20px;">
            <button class="btn btn-primary p-btn" type="button" onclick="confirm_sk()">确定收款</button>
            <button class="btn btn-white p-btn" type="button" onclick="empty()">清空</button>
        </div>
		</div>
  		<input type="hidden" name="pay_method" id="pay_method" />
  		<input type="hidden" name="dg_empno" id="dg_empno" />
  		<input type="hidden" name="line_member_id" id="line_member_id" />
	</div>
</div>
{/block} {block name="script"}
<script src="__JS__/jquery.form.js"></script>
<script src="__JS__/cash.js"></script>
<script>
	
	function confirm_sk(){
		var price=$("#price").val();
		if(price==""||isNaN(price)){
			layer.msg("请输入正确的账单金额!");
			return false;
		}
		var pay_method=$("#pay_method").val();
		if(pay_method==""){
			layer.msg("请选择支付方式!");
			return false;
		}
		if($("#key").val()==""){
			layer.msg("请选择会员!");
			return false;
		}
		var pay_money=$("#pay_money").val();
		if(pay_money==""||isNaN(pay_money)){
			layer.msg("请输入正确的付款金额!");
			return false;
		}
		if(pay_money<price){
			layer.msg("付款金额小于账单金额!");
			return false;
		}
		if(pay_method==2){
			if($("#key").val()==""){
				layer.msg("请输入正确的会员卡号!");
				return false;
			}
			var yue=parseFloat($("#money").text());
			if(yue<parseFloat(price)){
				layer.msg("余额不足!");
				return false;
			}
		}
		var zhaoling=parseFloat($("#zhaoling").text());
		var html='<div class="row" >'+
						'<div style="float: left;width:50%;text-align: center;">'+
							'<span id="sp_price" style="font-size:26px;font-weight:600;color:#35b12c">'+price+'</span>'+
							'<p>应收金额</p>'+
						'</div>'+
						'<div style="float: left;width:50%;text-align: center;">'+
							'<span id="sp_zhaoling" style="font-size:26px;font-weight:600;color:red">'+zhaoling+'</span>'+
							'<p>找零</p>'+
						'</div>'+
				   '</div>'+
				   '<div class="row" >'+
						'<div style="float: left;width:50%;text-align: center;">'+
							'<span>会员卡号</span>&nbsp<label>'+$("#no").text()+'</label>'+
						'</div>'+
						'<div style="float: left;width:50%;text-align: center;">'+
							'<span>充值后余额</span>&nbsp<label>'+ (parseFloat($("#money").text())+parseFloat($("#price").val()))+'</label>'+
						'</div>'+
				   '</div>'+
					'<div class="row" >'+
						'<div style="float: left;width:50%;text-align: center;">'+
							'<span>手机号</span>&nbsp<label>{$mobile}</label>'+
						'</div>'+
						'<div style="float: left;width:50%;text-align: center;">'+
							'<span>充值后积分</span>&nbsp<label>'+(parseFloat($("#score").text())+parseFloat($("#zs_score").val()))+'</label>'+
						'</div>'+
				   '</div>'+				   
				   '<div class="row" >'+
						'<div style="float: left;width:50%;text-align: center;">'+
							'<span>门店</span>&nbsp<label>{$store_name}</label>'+
						'</div>'+
						'<div style="float: left;width:50%;text-align: center;">'+
							'<span>收银员</span>&nbsp<label>{$mobile}</label>'+
						'</div>'+
				   '</div>';
		var index=layer.open({			
		  title: '确认充值',
		  zIndex :1999,
	 	  area: ['500px', '300px'] ,
		  content: html,
		  btn: ['确定','取消'],
		  yes: function(index, layero){
		    //按钮【按钮一】的回调
		    	$.ajax({
					url:'chongzhi',
					data:{type:6,price:price,pay_money:pay_money,zs_score:$("#zs_score").val(),no:$("#no").text(),zhaoling:zhaoling,pay_method:pay_method,dg_id:$("#dg_empno").val(),line_member_id:$("#line_member_id").val()},
					type:"post",
					success: function(dataa) {
						layer.close(index);
						if(pay_method==3||pay_method==4){
								var dt=dataa.data;
								if(pay_method==3){
									var ct='<div style="margin-left:100px;padding:0;"><img alt="扫码支付" src="http://paysdk.weixin.qq.com/example/qrcode.php?data='+dt.code_url+'" style="width:200px;height:200px;"/><div>';
								}else{
									var ct='<div style="margin-left:100px;padding:0;"><img alt="扫码支付" src="'+dt.code_url+'" style="width:200px;height:200px;"/><div>';
								}
								var index1=layer.open({
							 	  area: ['450px', '350px'] ,
							 	  zIndex :1999,
							 	  title:"扫码支付",
								  content: ct,
								  btn: ['支付完成','取消'],
								  yes: function(index, layero){
									  		$.ajax({
									  			type:"post",
									  			url:"confirm_pay",
									  			data:{type:6,sn:dt.sn},
									  			success:function(data){
									  				if(data==1){
									  					callback(dataa);
														empty();
									  				}else{
									  					layer.msg("充值失败");
									  				}
									  			}
									  		});
								  },btn2:function(index,layero){
								  	layer.close(index1);
								  }
								});
							}else{
								callback(dataa);
								empty();
							}
					}
				})
		  },btn2:function(index,layero){
		  	layer.close(index);
		  }
		});
	}
	
	
	function callback(data){
		if(data.code==200){
			var info=data.data;
			 var html='<div>'+
					'<div style="text-align: center;">'+
					'<i class="fa fa-check" style="color: #35b12c;font-size: 60px;font-weight: 600;"></i>'+
					'<p><span class="b_rs_pan">收款成功</span> </p>'+
					'</div>'+
					'<div class="form-group" style="padding-left: 100px;"><label class="col-sm-5 control-label">会员卡号：</label><div class="input-group col-sm-7">'+info.member_no+'</div></div>'+
					'<div class="form-group" style="padding-left: 100px;"><label class="col-sm-5 control-label">手机号：</label><div class="input-group col-sm-7">'+info.mobile+'</div></div>'+
					'<div class="form-group" style="padding-left: 100px;"><label class="col-sm-5 control-label">充值后余额：</label><div class="input-group col-sm-7">'+info.newblanceflg+'</div></div>'+
					'<div class="form-group" style="padding-left: 100px;"><label class="col-sm-5 control-label">充值后积分：</label><div class="input-group col-sm-7">'+info.newbonusflg+'</div></div>'+
					'<div class="form-group" style="padding-left: 100px;"><label class="col-sm-5 control-label">单号：</label><div class="input-group col-sm-7">'+info.log_no+'</div></div>'+
					'<div class="form-group" style="padding-left: 100px;"><label class="col-sm-5 control-label">交易时间：</label><div class="input-group col-sm-7">'+info.add_time+'</div></div>'+
					'<div class="form-group" style="padding-left: 100px;"><label class="col-sm-5 control-label">门店：</label><div class="input-group col-sm-7">'+info.store_name+'</div></div>'+
					'<div class="form-group" style="padding-left: 100px;"><label class="col-sm-5 control-label">操作员：</label><div class="input-group col-sm-7">'+info.skr+'</div></div>'+
				 '</div>';
				  var index=layer.open({
				  title: '收款成功',
				  zIndex :1999,
			 	  area: ['500px', '550px'] ,
				  content: html,
				  btn: ['我知道了','打印小票']
				  ,yes: function(index, layero){
				    layer.close(index);
			    	window.reload();
				  },btn2:function(index,layero){
				  	layer.msg("打印成功");
				  	window.reload();
				  }
			});
			
		}else{
			layer.msg(data.msg);
			window.reload();
		}
		
	}
	
	function call_back(msg){
		layer.msg(msg);
		layer.closeAll('iframe');
	}
	
	
</script>
{/block}